package cn.itcast;

import cn.itcast.n2.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "c.TestMultiLock")
public class TestMultiLock {
    public static void main(String[] args) {
        BigRoom bigRoom = new BigRoom();

        new Thread(() -> {
            bigRoom.study();
        },"小南").start();

        new Thread(() -> {
            bigRoom.sleep();
        },"小女").start();
    }
}

@Slf4j(topic = "c.BigRoom")
class BigRoom{

    private final Object studyRoom = new Object();
    private final Object sleepRoom = new Object();

    public void sleep(){
        synchronized (sleepRoom){
            log.debug("sleeping 2 小时");
            Sleeper.sleep(2);
        }
    }

    public void study(){
        synchronized (studyRoom){
            log.debug("study 1 小时");
            Sleeper.sleep(1);
        }
    }

}